#include <bits/stdc++.h>
using namespace std;
using uint=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;
const int N=1e6+5;

void solve(){
    int n;
    cin>>n;
    bool f=0;
    while(n--){
        string pass;
        cin>>pass;
        if(pass[0]==pass[5]&&pass[1]==pass[4]&&pass[2]==pass[3]){
            int sum=1;
            for(int i=0;i<6;i++){
                sum*=pass[i]-'0';
            }
            if(sum%6==0&&sum!=0){
                if((pass[0]-'0')*(pass[5]-'0')%3==0){
                    cout<<pass<<endl;
                    f=1;
                }
            }
        }
    }
    if(!f)cout<<"N0ne"<<endl;
    return;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();

    return 0;
}